﻿using System;
using System.Collections.Generic;
using Assets.Scripts.GtsScripts;
using Lua;
using UnityEngine;

// Token: 0x020001C2 RID: 450
public class GiantessManager
{
	// Token: 0x06000971 RID: 2417 RVA: 0x0005678A File Offset: 0x0005498A
	public GiantessManager()
	{
		GiantessManager.Instance = this;
	}

	// Token: 0x06000972 RID: 2418 RVA: 0x000567AE File Offset: 0x000549AE
	public void AddGiantess(Giantess gts)
	{
		this.gtsDictionary.Add(gts.id, gts);
		this.luaGtsDictionary.Add(gts.id, gts);
	}

	// Token: 0x06000973 RID: 2419 RVA: 0x000567D9 File Offset: 0x000549D9
	public void RemoveGiantess(int id)
	{
		this.gtsDictionary.Remove(id);
		this.luaGtsDictionary.Remove(id);
	}

	// Token: 0x06000974 RID: 2420 RVA: 0x000567F5 File Offset: 0x000549F5
	public IDictionary<int, Entity> GetLuaGtsList()
	{
		return this.luaGtsDictionary;
	}

	// Token: 0x06000975 RID: 2421 RVA: 0x00056800 File Offset: 0x00054A00
	public static Giantess GetRandomGiantess(EntityBase entity)
	{
		int count = GiantessManager.Instance.gtsDictionary.Count;
		int num = UnityEngine.Random.Range(0, count);
		int num2 = 0;
		Giantess giantess = null;
		foreach (KeyValuePair<int, Giantess> keyValuePair in GiantessManager.Instance.gtsDictionary)
		{
			if (giantess == null && keyValuePair.Value.gameObject.activeInHierarchy && (!entity.isGiantess || keyValuePair.Value.id != entity.id))
			{
				giantess = keyValuePair.Value;
			}
			if (num2 == num)
			{
				if (keyValuePair.Value.gameObject.activeInHierarchy && (!entity.isGiantess || keyValuePair.Value.id != entity.id))
				{
					return keyValuePair.Value;
				}
				num2++;
			}
			else
			{
				num2++;
			}
		}
		return giantess;
	}

	// Token: 0x06000976 RID: 2422 RVA: 0x00056924 File Offset: 0x00054B24
	public static Giantess FindClosestGiantess(EntityBase entity, float scale)
	{
		float num = 0.1f * scale;
		float num2 = 100f * scale;
		List<Giantess> list = null;
		while (num < num2 && (list == null || list.Count == 0))
		{
			list = GiantessManager.CheckRadius(entity, num);
			num *= 2f;
		}
		Giantess result = null;
		float num3 = num2;
		for (int i = 0; i < list.Count; i++)
		{
			float magnitude = (entity.myTransform.position - list[i].myTransform.position).magnitude;
			if (magnitude < num3)
			{
				result = list[i];
				num3 = magnitude;
			}
		}
		return result;
	}

	// Token: 0x06000977 RID: 2423 RVA: 0x000569D4 File Offset: 0x00054BD4
	public static List<Giantess> FindGiantessesInRadius(EntityBase entity, float radius)
	{
		radius *= entity.Height;
		return GiantessManager.CheckRadius(entity, radius);
	}

	// Token: 0x06000978 RID: 2424 RVA: 0x000569F4 File Offset: 0x00054BF4
	private static List<Giantess> CheckRadius(EntityBase entity, float radius)
	{
		Collider[] array = Physics.OverlapSphere(entity.myTransform.position, radius, Layers.gtsCapsuleMask);
		List<Giantess> list = new List<Giantess>();
		foreach (Collider collider in array)
		{
			Giantess giantess = collider.gameObject.GetComponent<GTSMovement>().giantess;
			if (giantess && !giantess.locked && entity.id != giantess.id)
			{
				list.Add(giantess);
			}
		}
		return list;
	}

	// Token: 0x04000F11 RID: 3857
	public static GiantessManager Instance;

	// Token: 0x04000F12 RID: 3858
	private Dictionary<int, Giantess> gtsDictionary = new Dictionary<int, Giantess>();

	// Token: 0x04000F13 RID: 3859
	private Dictionary<int, Entity> luaGtsDictionary = new Dictionary<int, Entity>();
}
